using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;

namespace Macaw.Wss3.DateFormatModifySolution
{
    class DateTimeControlAdapterFeature : SPFeatureReceiver
    {

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication;
            if (webApplication == null) return;

            // Make sure the job isn't already registered.
            foreach (SPJobDefinition oldjob in webApplication.JobDefinitions)
            {
                if (oldjob.Name == DateTimeControlAdapterJobDefinition.JobName)
                    oldjob.Delete();
            }

            DateTimeControlAdapterJobDefinition job = new DateTimeControlAdapterJobDefinition(DateTimeControlAdapterJobDefinition.JobName, webApplication)
            {
                Installing = true,
                Schedule = new SPOneTimeSchedule(DateTime.Now)
            };
            job.Update();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication;
            if (webApplication == null) return;

            // Make sure the job isn't already registered.
            foreach (SPJobDefinition oldjob in webApplication.JobDefinitions)
            {
                if (oldjob.Name == DateTimeControlAdapterJobDefinition.JobName)
                    oldjob.Delete();
            }

            DateTimeControlAdapterJobDefinition job = new DateTimeControlAdapterJobDefinition(DateTimeControlAdapterJobDefinition.JobName, webApplication)
            {
                Installing = false,
                Schedule = new SPOneTimeSchedule(DateTime.Now)
            };
            job.Update();
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {

        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {

        }
    }
}
